import 'package:cat_eye/config/color_config.dart';
import 'package:cat_eye/config/string_config.dart';
import 'package:cat_eye/util/sp_util.dart';
import 'package:flutter/material.dart';

/*
* @Package: provider
* @ClassName: app_Info_provider
* @Author: szj
* @CreateDate: 8/4/21 10:19 AM
*
* TODO 更改主题样式状态管理【provider】
*/
class AppInfoProvider with ChangeNotifier {
  AppInfoProvider() {
    //初始化主题颜色 名字随便起的！！！！
    a();
  }

  void a() async {
    //主题颜色
    _themeColor = await SpUtil.getDate<String>(StringConfig.SP_IS_COLOR_THEME);

    //主题模式
    bool value = await SpUtil.getDate<bool>(StringConfig.SP_IS_NIGHT_MODE);
    _themeMode = value ? 'dark' : 'light';

    print("szj主题颜色:$_themeColor\t主题模式:$themeMode");

    //主题色保存
    ColorConfig.themeColor = ColorConfig.themeColorMap[_themeColor];

    notifyListeners();
  }

  //主题颜色
  String _themeColor = '';

  //主题模式 白天/夜间
  String _themeMode = '';

  String get themeColor => _themeColor;

  String get themeMode => _themeMode;

  //设置主题颜色
  setTheme(String themeColor) {
    _themeColor = themeColor;
    notifyListeners();
  }

  ///设置夜间模式
  setNight(String mode) {
    _themeMode = mode;
    notifyListeners();
  }
}
